package com.hp.service;

import com.hp.dao.ConcernMapper;
import com.hp.pojo.Concern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConcernService {

    @Autowired private ConcernMapper concernMapper;

    public Map<String, Object> getALlConcern(int userId){
        Map<String, Object> allConcers=new HashMap<>();
        List<Concern> oneconcerns = new ArrayList<>();
        List<Concern> twoconcerns = new ArrayList<>();
        oneconcerns.addAll(concernMapper.seletOneConcern(userId));
        twoconcerns.addAll(concernMapper.seletTowConcern(userId));
        allConcers.put("oneconcern",oneconcerns);//sell
        allConcers.put("towConcern",twoconcerns);
        return allConcers;
    }

    public Map<String, Object> isConcern(int userId, int houseId){
        Map<String,Object> map = new HashMap<>();
        Concern concern = new Concern(0 , userId , houseId , 0);
        List<Concern> concerns = concernMapper.isConcern(concern);
        map.put("concern",concerns);
        System.out.println(concerns);
        return map;
    }


    public Map<String, String> delConcern(int userId, int houseId){
        concernMapper.delConcern(userId,houseId);

        Map<String,String> map = new HashMap<>();

        map.put("message","success");

        return map;
    }

    public Map<String, Object> addConcern(int houseId, int userId, int concernType){
        Concern concern = new Concern();
        concern.setHouseId(houseId);
        concern.setUserId(userId);
        concern.setConcernType(concernType);
        concernMapper.addConcern(concern);

        Map<String,Object> map = new HashMap<>();

        map.put("message","success");

        return map;
    }


}